package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
)

/*
实现了一个http的文件服务器
lzk 待实现错误统一处理
*/
func main() {
	http.HandleFunc("/list/", func(writer http.ResponseWriter, request *http.Request) {
		path := request.URL.Path[len("/list/"):]
		file, err := os.Open(path)
		if err != nil {
			panic(err)
		}
		defer file.Close()
		all, err := ioutil.ReadAll(file)
		if err != nil {
			panic(err)
		}

		write, err := writer.Write(all)
		if err != nil {
			panic(err)
		}
		fmt.Println(write)
	})
	http.ListenAndServe(":8888", nil)
}
